home *** CD-ROM | disk | FTP | other *** search
/ Champak 29 / Volume 29 - JOGO DISK .iso / Games / jungle_adventure.swf / scripts / __Packages / GameCollectable.as < prev    next >
Text File  |  2006-11-29  |  2KB  |  53 lines

  1. class GameCollectable extends SSObject
  2. {
  3.    var classID = SSGlobal.CLSID_COLLECTABLE;
  4.    var collisionMask = SSGlobal.CLSID_SHAPE | SSGlobal.CLSID_MAINCHAR;
  5.    var collected = false;
  6.    var radius = 15;
  7.    var bounciness = 0.5;
  8.    function GameCollectable()
  9.    {
  10.       super();
  11.    }
  12.    function updatePosition(elapsed)
  13.    {
  14.       var _loc3_ = this.x;
  15.       var _loc2_ = this.y;
  16.       this.checkCollisions(elapsed);
  17.       this.moveBy(this.velocity.x * this.motionTime,this.velocity.y * this.motionTime,0);
  18.       if(Math.abs(_loc3_ - this.x) < 0.5 && Math.abs(_loc2_ - this.y) < 0.5)
  19.       {
  20.          this.x = _loc3_;
  21.          this.y = _loc2_;
  22.          if((this.inMotion -= elapsed) <= 0)
  23.          {
  24.             this.cancelUpdates();
  25.             this.velocity.loc(0,0,0);
  26.          }
  27.       }
  28.    }
  29.    function checkCollision(obj)
  30.    {
  31.       var _loc2_ = undefined;
  32.       switch(obj.classID & 4294901760)
  33.       {
  34.          case SSGlobal.CLSID_SHAPE:
  35.             if(_loc2_ = SSCollision.sweepSphereToStaticShape(this,obj))
  36.             {
  37.                var _loc3_ = this.velocity.__get__length() * this.bounciness;
  38.                var _loc5_ = this.motionDir.dot(_loc2_.normal);
  39.                this.velocity.x = (this.motionDir.x - _loc2_.normal.x * _loc5_ * 2) * _loc3_;
  40.                this.velocity.y = (this.motionDir.y - _loc2_.normal.y * _loc5_ * 2) * _loc3_;
  41.                this.x = _loc2_.point.x;
  42.                this.y = _loc2_.point.y;
  43.             }
  44.             break;
  45.          case SSGlobal.CLSID_MAINCHAR:
  46.             if(SSCollision.sweepSphereToSphere(this,obj,true))
  47.             {
  48.                this.setCollected(obj);
  49.             }
  50.       }
  51.    }
  52. }
  53.